package edu.gatech.cs2340.group7.wheresmystuffapp.views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import edu.gatech.cs2340.group7.wheresmystuffapp.R;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DataManager;
import edu.gatech.cs2340.group7.wheresmystuffapp.presenters.AdminMainMenuPresenter;

public class AdminMainMenuView extends Activity implements View.OnClickListener {
	private String PACKAGE_NAME;
	private TextView tvAdminWelcome;
	private Button bLockAccount;
	private Button bCreateAdmin;
	private Button bRemoveUser;
	private Button bLogout;
	private Button bUnlockAccount;
	private AdminMainMenuPresenter myPresenter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_admin);

		initialize();
		PACKAGE_NAME = getApplication().getPackageName();
	}

	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {
		case R.id.b_create_admin:
			intent = new Intent(this, CreateAdminView.class);
			intent.setPackage(PACKAGE_NAME);
			myPresenter.createAdmin(intent);
			break;
		case R.id.b_lock_account:
			intent = new Intent(this, LoginView.class);
			myPresenter.lockAccount(intent);
			break;
		case R.id.b_remove_user:
			intent = new Intent(this, DeleteAccountView.class);
			myPresenter.removeUser(intent);
			break;
		case R.id.b_admin_logout:
			intent = new Intent(this, LoginView.class);
			myPresenter.logout(intent);
			break;
		case R.id.b_unlock_account:
			intent = new Intent(this, UnlockAccountView.class);
			myPresenter.unlockAccount(intent);
		}
	}

	/**
	 * Initializes all the views in the XML layout, and sets the listeners for the buttons
	 */
	private void initialize() {
		tvAdminWelcome = (TextView) findViewById(R.id.tv_admin_welcome);
		bLockAccount = (Button) findViewById(R.id.b_lock_account);
		bCreateAdmin = (Button) findViewById(R.id.b_create_admin);
		bRemoveUser = (Button) findViewById(R.id.b_remove_user);
		bLogout = (Button) findViewById(R.id.b_admin_logout);
		bUnlockAccount = (Button) findViewById(R.id.b_unlock_account);
		myPresenter = new AdminMainMenuPresenter(this);

		tvAdminWelcome.setText("Welcome " + DataManager.getCurrentAccountName());
		bLockAccount.setOnClickListener(this);
		bCreateAdmin.setOnClickListener(this);
		bRemoveUser.setOnClickListener(this);
		bLogout.setOnClickListener(this);
		bUnlockAccount.setOnClickListener(this);
	}

}
